{% extends 'base.html' %}

{% block content %}
<div class="edit-container">
    <h2>编辑文章</h2>
    <form method="post">
        <div class="form-group">
            <label for="title">标题</label>
            <input type="text" name="title"
                   placeholder="请输入标题" class="form-control"
                   value="{{ request.form['title'] or post['title'] }}">
        </div>

        <div class="form-group">
            <label for="content">内容</label>
            <textarea name="content" placeholder="请输入内容"
                      class="form-control" rows="10">{{ request.form['content'] or post['content'] }}</textarea>
        </div>

        <div class="button-group mt-4">
            <button type="submit" class="btn btn-primary">保存修改</button>

            <!-- 新增删除按钮 -->
            <a href="{{ url_for('delete', post_id=post['id']) }}"
               class="btn btn-danger ml-2"
               onclick="return confirm('确定要永久删除这篇文章吗？该操作不可恢复！')">
                <i class="fas fa-trash-alt"></i> 删除文章
            </a>
        </div>
    </form>

    <hr class="my-5">

    <!-- 或者使用表单形式 -->
    {# <form action="{{ url_for('delete', post_id=post['id']) }}" method="post" class="mt-3">
        <button type="submit" class="btn btn-danger"
                onclick="return confirm('确定要永久删除这篇文章吗？该操作不可恢复！')">
            <i class="fas fa-trash-alt"></i> 永久删除文章
        </button>
    </form> #}
</div>

<style>
    .edit-container {
        max-width: 800px;
        margin: 0 auto;
    }

    .button-group {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    textarea {
        resize: vertical;
        min-height: 300px;
    }
</style>
{% endblock %}